package com.tongyi.lizhishop.activitys;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.tongyi.lizhishop.beans.Item;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import com.tongyi.lizhishop.R;
import com.tongyi.lizhishop.common.RecycleViewActivity;

import java.util.ArrayList;

public class MyWalletActivity extends RecycleViewActivity implements View.OnClickListener, MultiItemTypeAdapter.OnItemClickListener {


    ArrayList<Item> itemDatas = new ArrayList<>();
    private MultiItemTypeAdapter multiItemTypeAdapter;
    private CommonAdapter<Item> adapter;
    private TextView rightTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitleBarView(titlebar, "我的余额");
        initView();
        loadData();
    }

@Override
    public  void loadData() {
        multipleStatusView.showContent();
        for (int i = 0; i < 100; i++) {
            itemDatas.add(new Item("你收到一条消息" + i));
        }
        multiItemTypeAdapter.notifyDataSetChanged();

    }

    private static final String TAG = "AlertMessageActivity";

    private void initView() {
        rightTextView = titlebar.getRightTextView();
        rightTextView.setText("卡包");
        rightTextView.setOnClickListener(this);

        multipleStatusView.showLoading();
        refreshLayout.setEnableLoadmore(false);
        refreshLayout.setEnableRefresh(false);
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        recyclerview.setItemAnimator(new DefaultItemAnimator());
        recyclerview.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        multiItemTypeAdapter = new MultiItemTypeAdapter(this, itemDatas);
        multiItemTypeAdapter.addItemViewDelegate(new ItemViewDelegate() {
            @Override
            public int getItemViewLayoutId() {
                return R.layout.activity_mywallet_recycleview_item;
            }

            @Override
            public boolean isForViewType(Object item, int position) {
                return position == 0;
            }

            @Override
            public void convert(ViewHolder holder, Object o, int position) {

            }
        });
        multiItemTypeAdapter.addItemViewDelegate(new ItemViewDelegate() {
            @Override
            public int getItemViewLayoutId() {
                return R.layout.activity_mywallet_recycleview_item_common;
            }

            @Override
            public boolean isForViewType(Object item, int position) {
                return position != 0;
            }

            @Override
            public void convert(ViewHolder holder, Object o, int position) {

            }
        });
        recyclerview.setAdapter(multiItemTypeAdapter);
        multiItemTypeAdapter.setOnItemClickListener(this);
    }


    @Override
    public void onClick(View v) {
        if(v==rightTextView){
            ActivityUtils.startActivity(this,MyICCardActivity.class);
        }
    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
        if(position==0){
            //提现
            ActivityUtils.startActivity(this,WithDrawActivity.class);
        }
    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }
}
